<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
	<head>
		<title>Compare Element Positions</title>
        <style type='text/css'>
            body {font-family: verdana}
            div {
            	border: solid 1px black;
				margin: 5px;
				padding: 5px;
				font-size: 12px;
            }
			.red {
				background-color: red;
			}
			.green {
				background-color: green;
			}
			.hide {
				display: none;
			}
			h3 {
				margin: 20px 0px 0px 0px;
			}
			th {
				padding: 0px 5px;
				color: gray;
			}
			td {
				padding: 0px 5px;
			}
        </style>
	</head>
	<body>
<p>Click 2 elements to compare them.</p>
<pre>
<code>$('.red').compare($('.green')) = <span id='result'></span></code>
</pre>
<div id="demo-html">
<div>
	A
	<div>A.1</div>
	<div>A.2</div>
</div>
<div>
	B
</div>
</div>
<h3 class='hide'>Key</h3>
<table class='hide'>
	<tr><th>Bits</th><th>Number</th><th>Meaning</th></tr>
	<tr><td>000000</td><td>0</td><td>Elements are identical.</td></tr>
	<tr><td>000001</td><td>1</td><td>The nodes are in different documents (or one is outside of a document).</td></tr>
	<tr><td>000010</td><td>2</td><td>Node B precedes Node A.</td></tr>
	<tr><td>000100</td><td>4</td><td>Node A precedes Node B.</td></tr>
	<tr><td>001000</td><td>8</td><td>Node B contains Node A.</td></tr>
	<tr><td>010000</td><td>16</td><td>Node A contains Node B.</td></tr>
	
</table>

		<script type='text/javascript' 
                src='../../../steal/steal.js'>   
        </script>
<script id="demo-source" type='text/javascript'>
steal('jquery/dom/compare').then(function(){
	var placing = 'red'
	//on click, set red and green and compare positions
	$('div').click(function(ev){
	  var next = placing == 'red' ? 'green' : 'red';
	  $('.'+placing).removeClass(placing)
	  $(this).addClass(placing) 
	  placing = next
	  ev.stopPropagation();
	  //don't worry about repeat queries for simple example
	  if($('.green').length){
	    $("#result").text(  $('.red').compare($('.green')) )
	  }
	})
	
	$(function(){
		if(window.parent == window){
			$('.hide').show()
		}
	})
})

</script>
	</body>
</html>